

var ajaxObj = new XMLHttpRequest()
ajaxObj.open('get','./mock/data.json',true)
ajaxObj.send()
ajaxObj.onreadystatechange = function () {
    if(ajaxObj.readyState==4 && ajaxObj.status==200){
        let data = JSON.parse(ajaxObj.responseText)

        ready(data)
    }
}

var goodsList = document.querySelector('.goods-list')



//ajax获取成功后执行
function ready(data) {

    //生活研究所列表数据
    let beltList = document.querySelector('.belt-list')
    let beltTpl = template('beltTpl', data);
    beltList.innerHTML = beltTpl


    //每日好店数据
    let goodsList = document.querySelector('.goods-list')
    let goodsTpl = template('goodsTpl', data);
    goodsList.innerHTML = goodsTpl

    let shoppingList = document.querySelector('.shopping-list')
    let shoppingTpl = template('shoppingTpl', data);
    shoppingList.innerHTML = shoppingTpl

    add(goodsList)
    add(shoppingList)
}
//goods第二行加样式
function add(eleList) {
    for (let i=0;i<eleList.querySelectorAll('li').length;i++){
        if(i>2){
            eleList.querySelectorAll('li')[i].classList.add('seconds')
        }
    }
}


